import service from '@/server/index.js'

// 登录
export const login = (params = {}) => {
  return service({
    url: '/user/login',
    method: 'POST',
    data: params,
    setting: {
      isToken: false
    }
  });
};

// 注册
export const register = (params = {}) => {
  return service({
    url: '/user/register',
    method: 'POST',
    data: params,
    setting: {
      isToken: false
    }
  });
}

// 退出方法
export function logout() {
  return service({
    url: "/user/logout",
    method: "POST",
    setting: {
      isToken: true,
      isRefresh: true
    },
  });
}

// 刷新token
export const refreshToken = () => {
  return service({
    url: "/user/refreshToken",
    method: "POST",
    setting: {
      isToken: false,
      isRefresh: true
    }
  });
}

// 获取用户信息
export const getInfo = () => {
  return service({
    url: "/user",
    method: "GET",
    setting: {
      isToken: true
    }
  });
};

// 分页查询用户
export const getUserList = (params = {}) => {
  return service({
    url: "/user/page",
    method: "GET",
    params: params,
    setting: {
      isToken: true
    }
  });
};

// 新增用户
export const add = (params = {}) => {
  return service({
    url: "/user",
    method: "POST",
    data: params,
    setting: {
      isToken: true
    }
  });
};

// 修改用户
export const update = (params = {}) => {
  return service({
    url: "/user",
    method: "PUT",
    data: params,
    setting: {
      isToken: true
    }
  });
};

// 删除用户
export const del = (id) => {
  return service({
    url: "/user/" + id,
    method: "DELETE",
    setting: {
      isToken: true
    }
  });
}

// 修改个人信息
export const updateInfo = (params = {}) => {
  return service({
    url: "/user/info",
    method: "PUT",
    data: params,
    setting: {
      isToken: true
    }
  });
};

// 修改密码
export const updatePassword = (params = {}) => {
  return service({
    url: "/user/password",
    method: "PUT",
    data: params,
    setting: {
      isToken: true
    }
  });
};

// 获取所有角色
export const getRoleList = () => {
  return service({
    url: "/user/role",
    method: "GET",
    setting: {
      isToken: false
    }
  });
};

// 查询列表
export const getList = () => {
  return service({
    url: "/user/list",
    method: "GET",
    setting: {
      isToken: true
    }
  });
};

// 获取验证码
export const captcha = () => {
  return service({
    url: "/captcha",
    method: "GET",
    setting: {
      isToken: false
    }
  });
};

// 验证码验证
export const captchaVerify = (params = {}) => {
  return service({
    url: "/captcha/verify",
    method: "POST",
    data: params,
    setting: {
      isToken: false
    }
  });
};
